package pool;

import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduleThreadPoolTest {

    public static void main(String[] args) {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
        for(int i=0;i<2;i++){
            System.out.println(new Date().toLocaleString());
            scheduledExecutorService.schedule(new MyTask("FOO"+i), 10, TimeUnit.SECONDS);
        }
    }
}

class MyTask implements Runnable{

    private String taskName;

    public MyTask(String taskName) {
        this.taskName = taskName;
    }

    @Override
    public void run() {
        System.out.println("taskName=" + taskName + ",startTime=" + new Date().toLocaleString());
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("taskName=" + taskName + ",endTime=" + new Date().toLocaleString());
    }
}
